package com.example.novelweb.controller;

import com.example.novelweb.common.BaseResponse;
import com.example.novelweb.common.ErrorCode;
import com.example.novelweb.exception.ThrowUtils;
import com.example.novelweb.model.dto.commentLike.CommentLikeAddRequest;
import com.example.novelweb.service.CommentlikeService;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/commentlike")
public class CommentLikeController {

  @Resource
  CommentlikeService commentlikeService;


  @ApiImplicitParam(name = "Authorization", value = "Authorization",required = true, dataType = "String",paramType="header")
  @GetMapping("/novel")
  public BaseResponse<List<Long>> listCommentIsLike(Long novelId, HttpServletRequest httpServletRequest) {
    ThrowUtils.throwIf(novelId ==null || novelId<=0, ErrorCode.PARAMS_ERROR);

    return commentlikeService.getCommentIdList(novelId);
  }

  @ApiImplicitParam(name = "Authorization", value = "Authorization",required = true, dataType = "String",paramType="header")
  @PostMapping("/add")
  public BaseResponse<Boolean> addCommentLike(@RequestBody CommentLikeAddRequest addRequest, HttpServletRequest httpServletRequest) {
    ThrowUtils.throwIf(addRequest == null, ErrorCode.PARAMS_ERROR,"param id is null or invalid");
    Long novelId = addRequest.getNovelId();
    Long commentId = addRequest.getCommentId();
    ThrowUtils.throwIf(novelId==null || novelId<=0 || commentId==null || commentId<=0,ErrorCode.PARAMS_ERROR);
    return commentlikeService.add(commentId,novelId);
  }

  @ApiImplicitParam(name = "Authorization", value = "Authorization",required = true, dataType = "String",paramType="header")
  @PostMapping("/del")
  public BaseResponse<Boolean> delCommentLike(@RequestParam("commentId") Long commentId,HttpServletRequest httpServletRequest) {
    ThrowUtils.throwIf(commentId == null || commentId <= 0, ErrorCode.PARAMS_ERROR,"param id is null or invalid");
    return commentlikeService.del(commentId);
  }



}
